home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / i-c.ads < prev    next >
Text File  |  1996-01-30  |  5KB  |  166 lines

  1. -----------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT COMPILER COMPONENTS                         --
  4. --                                                                          --
  5. --                         I N T E R F A C E S . C                          --
  6. --                                                                          --
  7. --                                 S p e c                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.10 $                              --
  10. --                                                                          --
  11. -- This specification is adapted from the Ada Reference Manual for use with --
  12. -- GNAT.  In accordance with the copyright of that document, you can freely --
  13. -- copy and modify this specification,  provided that if you redistribute a --
  14. -- modified version,  any changes that you have made are clearly indicated. --
  15. --                                                                          --
  16. ------------------------------------------------------------------------------
  17.  
  18. with Unchecked_Conversion;
  19.  
  20. package Interfaces.C is
  21. pragma Pure (C);
  22.  
  23.    --  Declaration's based on C's <limits.h>
  24.  
  25.    CHAR_BIT  : constant := 8;
  26.    SCHAR_MIN : constant := -128;
  27.    SCHAR_MAX : constant := 127;
  28.    UCHAR_MAX : constant := 255;
  29.  
  30.    --  Signed and Unsigned Integers. Note that in GNAT, we have ensured that
  31.    --  the standard predefined Ada types correspond to the standard C types
  32.  
  33.    type int   is new Integer;
  34.    type short is new Short_Integer;
  35.    type long  is new Long_Integer;
  36.  
  37.    type signed_char is range SCHAR_MIN .. SCHAR_MAX;
  38.    for signed_char'Size use CHAR_BIT;
  39.  
  40.    type unsigned       is mod 2 ** Integer'Size;
  41.    type unsigned_short is mod 2 ** Short_Integer'Size;
  42.    type unsigned_long  is mod 2 ** Long_Integer'Size;
  43.  
  44.    type unsigned_char is mod (UCHAR_MAX + 1);
  45.    for unsigned_char'Size use CHAR_BIT;
  46.  
  47.    subtype plain_char is unsigned_char; -- ??? should be parametrized
  48.  
  49.    type ptrdiff_t is new Integer;       -- ??? should be parametrized
  50.  
  51.    type size_t is mod 2 ** 32;          -- ??? should be parametrized
  52.  
  53.    --  Floating-Point
  54.  
  55.    type C_float     is new Float;
  56.  
  57.    type double      is new Standard.Long_Float;
  58.  
  59.    type long_double is new Standard.Long_Long_Float;
  60.  
  61.    ----------------------------
  62.    -- Characters and Strings --
  63.    ----------------------------
  64.  
  65.    type char is new Character;
  66.  
  67.    nul : constant char := char'First;
  68.  
  69.    function To_C   (Item : Character) return char;
  70.    function To_Ada (Item : char)      return Character;
  71.  
  72.    type char_array is array (size_t range <>) of aliased char;
  73.    pragma Pack (char_array);
  74.    for char_array'Component_Size use CHAR_BIT;
  75.  
  76.    function Is_Nul_Terminated (Item : in char_array) return Boolean;
  77.  
  78.    function To_C
  79.      (Item       : in String;
  80.       Append_Nul : in Boolean := True)
  81.       return       char_array;
  82.  
  83.    function To_Ada
  84.      (Item     : in char_array;
  85.       Trim_Nul : in Boolean := True)
  86.       return     String;
  87.  
  88.    procedure To_C
  89.      (Item       : in String;
  90.       Target     : out char_array;
  91.       Count      : out size_t;
  92.       Append_Nul : in Boolean := True);
  93.  
  94.    procedure To_Ada
  95.      (Item     : in char_array;
  96.       Target   : out String;
  97.       Count    : out Natural;
  98.       Trim_Nul : in Boolean := True);
  99.  
  100.    ------------------------------------
  101.    -- Wide Character and Wide String --
  102.    ------------------------------------
  103.  
  104.    type wchar_t is new Wide_Character;
  105.    wide_nul : constant wchar_t := wchar_t'First;
  106.  
  107.    function To_C   (Item : in Wide_Character) return wchar_t;
  108.    function To_Ada (Item : in wchar_t)        return Wide_Character;
  109.  
  110.    type wchar_array is array (size_t range <>) of aliased wchar_t;
  111.    pragma Pack (wchar_array);
  112.  
  113.    function Is_Nul_Terminated (Item : in wchar_array) return Boolean;
  114.  
  115.    function To_C
  116.      (Item       : in Wide_String;
  117.       Append_Nul : in Boolean := True)
  118.       return       wchar_array;
  119.  
  120.    function To_Ada
  121.      (Item     : in wchar_array;
  122.       Trim_Nul : in Boolean := True)
  123.       return     Wide_String;
  124.  
  125.    procedure To_C
  126.      (Item       : in Wide_String;
  127.       Target     : out wchar_array;
  128.       Count      : out size_t;
  129.       Append_Nul : in Boolean := True);
  130.  
  131.    procedure To_Ada
  132.      (Item     : in wchar_array;
  133.       Target   : out Wide_String;
  134.       Count    : out Natural;
  135.       Trim_Nul : in Boolean := True);
  136.  
  137.    Terminator_Error : exception;
  138.  
  139. private
  140.  
  141.    function Character_To_char is new
  142.      Unchecked_Conversion (Character, char);
  143.  
  144.    function char_To_Character is new
  145.      Unchecked_Conversion (char, Character);
  146.  
  147.    function wchar_t_To_Wide_Character is new
  148.      Unchecked_Conversion (wchar_t, Wide_Character);
  149.  
  150.    function Wide_Character_To_wchar_t is new
  151.      Unchecked_Conversion (Wide_Character, wchar_t);
  152.  
  153.    function To_C (Item : Character) return char
  154.      renames Character_To_char;
  155.  
  156.    function To_Ada (Item : char) return Character
  157.      renames char_To_Character;
  158.  
  159.    function To_C (Item : in Wide_Character) return wchar_t
  160.      renames Wide_Character_To_wchar_t;
  161.  
  162.    function To_Ada (Item : in wchar_t) return Wide_Character
  163.      renames wchar_t_To_Wide_Character;
  164.  
  165. end Interfaces.C;
  166.